from django.db import models
from utils.model import BaseModel
from user.models import User
from django.conf import settings

# Create your models here.
class Product(BaseModel):
    name = models.CharField(max_length=32,verbose_name="会员商品名")
    vip_type = models.IntegerField(choices=[(1,"黄金会员"),(2,"至尊会员")], default=1, verbose_name="会员类型")
    price = models.DecimalField(max_digits=6, decimal_places=2,verbose_name='商品原价')
    real_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="商品实价")
    order = models.IntegerField(default=0,verbose_name='显示顺序')
    validity_date = models.IntegerField(verbose_name='有效日期')

    class Meta:
        db_table = 'db_product'
        verbose_name_plural = '会员商品表'

    def __str__(self):
        return self.name


class Order(BaseModel):
    """订单模型"""
    status_choices = (
        (0, '未支付'),
        (1, '已支付'),
        (2, '已取消'),
        (3, '超时取消'),
    )
    pay_choices = (
        (1, '支付宝'),
        (2, '微信支付'),
    )
    subject = models.CharField(max_length=150, verbose_name="订单标题")
    out_trade_no = models.CharField(max_length=64, verbose_name="订单号", unique=True)
    trade_no = models.CharField(max_length=64, null=True, verbose_name="流水号")
    order_status = models.SmallIntegerField(choices=status_choices, default=0, verbose_name="订单状态")
    pay_type = models.SmallIntegerField(choices=pay_choices, default=1, verbose_name="支付方式")
    user = models.ForeignKey(User, related_name='user_orders', on_delete=models.DO_NOTHING, db_constraint=False,
                             verbose_name="下单用户")
    product=models.ForeignKey(to="Product", related_name="produc_orders",db_constraint=False,
                              on_delete=models.DO_NOTHING,verbose_name="购买的商品")
    price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="商品原价")
    real_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="商品实价")
    vip_type = models.IntegerField(choices=[(1,"黄金会员"),(2,"至尊会员")], default=1, verbose_name="会员类型")



    class Meta:
        db_table = "db_order"
        verbose_name_plural = "订单记录表"

    def __str__(self):
        return "%s - ￥%s" % (self.subject, self.real_price)
